package com.fjut.zr.judge_system.OJ;

import com.fjut.zr.judge_system.OJ.Submitter.OJSubmitter;
import com.fjut.zr.judge_system.POJO.VO.OJSubmitinfo;
import com.fjut.zr.judge_system.Util.ApplicationContextHelper;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class Ojudge {
    //创建测评机组
    List<OjSubmitter> listOjSubmitters=new ArrayList<OjSubmitter>();
    //创建阻塞队列组
    List<BlockingQueue<OJSubmitinfo>> queue = new ArrayList<BlockingQueue<OJSubmitinfo>>();
    public Ojudge()//初始化
    {
        String ojkeys[] = OJSubmitter.oj_keys;
        for(int j = 0;j < ojkeys.length; j++){
            listOjSubmitters.add(new OjSubmitter(j, j * 10 + j,this));
            queue.add(new LinkedBlockingQueue<OJSubmitinfo>());
        }
        DO();
    }

    public int addSubmit(OJSubmitinfo info, int oj){
        try {
            System.out.println("按入提交信息");
            queue.get(oj).put(info);
        } catch (InterruptedException e) {
            // Tool.log(e);
        }
        return 1;
    }
    private void DO(){
        for (OjSubmitter ojSubmitter : listOjSubmitters) {
            Thread t1 = new Thread(ojSubmitter);
            ojSubmitter.setSelfThread(t1);//传线程给测评机以便读取线程id
            t1.start();
        }
    }
}
